-
Notifications
You must be signed in to change notification settings - Fork 181
SUM aggregation enhancement on operations with literal #3971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Heng Qian <qianheng@amazon.com>
Signed-off-by: Heng Qian <qianheng@amazon.com>
| /** | ||
| * Ignore queries that are not supported by Calcite. Ignore q30 because of too much script push | ||
| * down, which will cause ResourceMonitor restriction. | ||
| * Ignore queries that are not supported by Calcite. TODO: need to investigate on why q30 trigger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calcite will produce lots of recyclable memory garbage during its planning and implementation process. For q30, it produces around 70 mb in optimizing + 30 mb in implementation on my local test, which can all be GC.
So I think, for Calcite, the ResourceMonitor's memory health check is unpredictable and less reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResourceMonitor protect physical operator, how it related to Calcite optimizing/implementation logica?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sql/opensearch/src/main/java/org/opensearch/sql/opensearch/monitor/OpenSearchMemoryHealthy.java
Lines 53 to 58 in 7892b90
| static class MemoryUsage { | |
| public long usage() { | |
| final long freeMemory = Runtime.getRuntime().freeMemory(); | |
| final long totalMemory = Runtime.getRuntime().totalMemory(); | |
| return totalMemory - freeMemory; | |
| } |
ResourceMonitor get the memory usage by using total memory - free memory. While the whole process of a query(even other queries previous to the current one) will accumulate the memory usage until GC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've submitted a PR #3983 to fix the issue
|
|
||
| /** See source in {@link org.apache.calcite.rel.core.Aggregate::computeSelfCost} */ | ||
| private static float getAggMultiplier(PushDownAction action) { | ||
| List<AggregateCall> aggCalls = ((Aggregate) action.digest).getAggCallList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comments before and after code from calcite
// START CALCITE
...
your code
// END CALCITE
| // For script aggregation, we need to multiply the multiplier by 2.2 to make up the cost. As we | ||
| // prefer to have non-script agg push down after optimized by {@link PPLAggregateConvertRule} | ||
| if (((AggPushDownAction) action.action).isScriptPushed) { | ||
| multiplier *= 2.2f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.2f magic number, Can i be changed in future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually it doesn't need any change unless we met some edge case(like the final plan doesn't satisfy our expectation) where I need refactor it.
Similar to the factor we add in filter script push down:
| /** | ||
| * Ignore queries that are not supported by Calcite. Ignore q30 because of too much script push | ||
| * down, which will cause ResourceMonitor restriction. | ||
| * Ignore queries that are not supported by Calcite. TODO: need to investigate on why q30 trigger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResourceMonitor protect physical operator, how it related to Calcite optimizing/implementation logica?
| import org.immutables.value.Value; | ||
|
|
||
| /** | ||
| * Planner rule that converts specific aggCall to a more efficient expressions, which includes: - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add UT
| * NUMBER, Don't support this because of integer division - MAX/MIN(FIELD [+|-|*|+|/] NUMBER) -> | ||
| * MAX/MIN(FIELD) [+|-|*|+|/] NUMBER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format java doc.
| /** | ||
| * Planner rule that converts specific aggCall to a more efficient expressions, which includes: - | ||
| * SUM(FIELD + NUMBER) -> SUM(FIELD) + NUMBER * COUNT() - SUM(FIELD - NUMBER) -> SUM(FIELD) - NUMBER | ||
| * * COUNT() - SUM(FIELD * NUMBER) -> SUM(FIELD) * NUMBER - SUM(FIELD / NUMBER) -> SUM(FIELD) / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SUM(FILED / NUMBER) -> SUM(FIELD) / NUMBER, does it work for float/double?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, they also have precision issue, e.g:
assuming SUM(a / 0.2) and the table has a = 0.1 for its all 3 rows. The execution could be present:
0.1 / 0.2 * 3 = 1.5
0.1 * 3 / 0.2 = 1.5000000000000002
Signed-off-by: Heng Qian <qianheng@amazon.com>
Signed-off-by: Heng Qian <qianheng@amazon.com>
# Conflicts: # integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteExplainIT.java
Signed-off-by: Heng Qian <qianheng@amazon.com>
# Conflicts: # integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteExplainIT.java
|
@penghuo Please take another look. |
|
The backport to To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/sql/backport-2.19-dev 2.19-dev
# Navigate to the new working tree
pushd ../.worktrees/sql/backport-2.19-dev
# Create a new branch
git switch --create backport/backport-3971-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 892355190687033b0f29bae624182c1ba204bf96
# Push it to GitHub
git push --set-upstream origin backport/backport-3971-to-2.19-dev
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/sql/backport-2.19-devThen, create a pull request where the |
…oject#3971) * SUM aggregation enhancement on operations with literal Signed-off-by: Heng Qian <qianheng@amazon.com> * Fix CI Signed-off-by: Heng Qian <qianheng@amazon.com> * Keep ignoring q30 for Calcite Signed-off-by: Heng Qian <qianheng@amazon.com> * Add UT for PPLAggregateConvertRule Signed-off-by: Heng Qian <qianheng@amazon.com> * Add UT for PPLAggregateConvertRule Signed-off-by: Heng Qian <qianheng@amazon.com> * Spotless check Signed-off-by: Heng Qian <qianheng@amazon.com> --------- Signed-off-by: Heng Qian <qianheng@amazon.com> Co-authored-by: Mitchell Gale <mitchell.gale@improving.com> (cherry picked from commit 8923551)
…teral (#3971) (#4104) * SUM aggregation enhancement on operations with literal (#3971) * SUM aggregation enhancement on operations with literal Signed-off-by: Heng Qian <qianheng@amazon.com> * Fix CI Signed-off-by: Heng Qian <qianheng@amazon.com> * Keep ignoring q30 for Calcite Signed-off-by: Heng Qian <qianheng@amazon.com> * Add UT for PPLAggregateConvertRule Signed-off-by: Heng Qian <qianheng@amazon.com> * Add UT for PPLAggregateConvertRule Signed-off-by: Heng Qian <qianheng@amazon.com> * Spotless check Signed-off-by: Heng Qian <qianheng@amazon.com> --------- Signed-off-by: Heng Qian <qianheng@amazon.com> Co-authored-by: Mitchell Gale <mitchell.gale@improving.com> (cherry picked from commit 8923551) * Fix Compiling Signed-off-by: Heng Qian <qianheng@amazon.com> * Fix Compiling Signed-off-by: Heng Qian <qianheng@amazon.com> * Fix Compiling Signed-off-by: Heng Qian <qianheng@amazon.com> --------- Signed-off-by: Heng Qian <qianheng@amazon.com> Co-authored-by: Mitchell Gale <mitchell.gale@improving.com> Co-authored-by: MitchellGale-BitQuill <104795536+mitchellgale-bitquill@users.noreply.github.com>
Description
SUM aggregation enhancement on operations with literal
Related Issues
Resolves #3967
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.